using System;
using System.Collections.Generic;
using System.Web.Mvc;
using FwkLight.Web.UserSession;
using MvcContrib.FluentHtml;
using MvcContrib.FluentHtml.Behaviors;
using StructureMap;


namespace FwkLight.Web.MVC
{
  public class BaseViewBase : ViewPage
  {
    
  }

  public class BaseView<T> : BaseViewBase, IViewModelContainer<T> where T : class
  {
    public new ViewDataDictionary<T> ViewData { get { throw new NotImplementedException(); } }

    private readonly IDisplayErrorMessages _displayErrorMessages;
    private readonly IDisplaySuccessMessages _displaySuccessMessages;

    public BaseView ( )
    {
      _displayErrorMessages = ObjectFactory.GetInstance<IDisplayErrorMessages>();
      _displaySuccessMessages = ObjectFactory.GetInstance<IDisplaySuccessMessages>();
    }

    public IDisplayErrorMessages Errors
    {
      get
      {
        _displayErrorMessages.ViewContext = ViewContext;
        _displayErrorMessages.TempData = TempData;
        return _displayErrorMessages;
      }
    }

    public IDisplaySuccessMessages Messages
    {
      get
      {
        _displaySuccessMessages.ViewContext = ViewContext;
        _displaySuccessMessages.TempData = TempData;
        return _displaySuccessMessages;
      }
    }

    public new T Model
    {
      get
      {
        return base.ViewData.Model as T;
      }
    }

    public ModelStateDictionary ModelState
    {
      get
      {
        return base.ViewData.ModelState;
      }
    }

    public T ViewModel
    {
      get { return Model; }
    }

    public IEnumerable<IBehaviorMarker> Behaviors
    {
      get { return new List<IBehaviorMarker>(); }
    }

    public string HtmlNamePrefix { get; set; }
  }
}